<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 

<%@ page import="com.semanticvoid.lifelogger.karma.search.interfaces.ISearch" %>
<%@ page import="com.semanticvoid.lifelogger.configuration.Constants" %>
<%@ page import="com.semanticvoid.lifelogger.configuration.ConfigManager" %>
<%@ page import="com.semanticvoid.lifelogger.entity.BrowseHistoryEntity" %>
<%@ page import="java.util.Vector" %>
<%@ page import="java.util.Date" %>
<%@ page import="com.semanticvoid.lifelogger.karma.search.factory.SearchFactory" %>

<jsp:include page="init.jsp" />

<%@include file="/WEB-INF/jspf/sHeader.jspf" %>

<% Date d_start = new Date(); %>

<% 
String query = request.getParameter("q");

if(query == null || query.equals("")) {
    response.sendRedirect("index.jsp");
}

String order = request.getParameter("o");

if(order == null) {
    order = "none";
}

short type = Constants.ITEM_TYPE_FOR_ALL;
ConfigManager mgr = ConfigManager.getInstance();
%>

<%
ISearch searcher = null;

if(order.equalsIgnoreCase("timedamp")) {
    searcher = new SearchFactory().produceSearcher(Constants.DECORATOR_TIME_DAMPER);
} else if(order.equalsIgnoreCase("date")) {
    searcher = new SearchFactory().produceSearcher(Constants.DECORATOR_TIME_SORT_DESC);
} else {
    searcher = new SearchFactory().produceSearcher(mgr.getSearchDecorators());
}

session.setAttribute("query", query);
session.setAttribute("searcher", searcher);
session.setAttribute("type", type);
session.setAttribute("fdate", null);
session.setAttribute("tdate", null);
%>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Search for <%= query %> - Zephyr</title>
        
        <jsp:include page="WEB-INF\jspf\javascriptIncludes.jspf" />
        
        <style>
            body,td,a,p,.h{font-family:arial,sans-serif}
            .h{font-size:20px}
            .h{color:#3366cc}
            .q{color:#00c}
        </style>
        
    </head>
    <body bgcolor="" style="">
        
        <table border="0" width="100%">
            <tr>
                <td height="30" colspan="3" style="vertical-align: center; background-color: #f8dfa8">
                    &nbsp;<b>Searching for </b><i><%= query %></i>
                </td>
            </tr>
            <tr>
                <td style="vertical-align: top;" colspan="2" width="70%">
                    <jsp:include page="search/browseHistorySearch.jsp"/>
                </td>
                <td style="vertical-align: top;" width="25%">
                    <jsp:include page="search/searchHistorySearch.jsp"/>
                </td>
            </tr>
        </table>        
    </body>
</html>


<%@include file="/WEB-INF/jspf/sFooter.jspf" %>

<%
    Date d_end = new Date(); 
    double d_diff_secs = (double)(d_end.getTime() - d_start.getTime()) / (double)1000;
%>

<div align="center">
    <br>
    <font size="2"> This page was generated in <%= d_diff_secs %> seconds</font>
</div>